namespace SmartSoft.ADP
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class DmHdDataAccess
    {
        private WSDmHdDataAccess.WSDmHdDataAccess wDataAcess = new WSDmHdDataAccess.WSDmHdDataAccess();
        private SmartSoft.DAL.DmHdDataAccess oDataAcess = new SmartSoft.DAL.DmHdDataAccess();

        public DmHdDataAccess()
        {
            wDataAcess.Url = wDataAcess.Url.Replace("localhost", AdapterInstance.ServerIp);
        }

        //public bool DeleteRowDetail(SqlConnection po_Connection, SqlTransaction po_Transaction, object po_KeyCode)
        //{
        //    if (AdapterInstance.IsRemoteConnected)
        //    {
        //        return wDataAcess.DeleteRowDetail(po_Connection, po_Transaction, po_KeyCode == DBNull.Value ? string.Empty : po_KeyCode);
        //    }
        //    else
        //    {
        //        return oDataAcess.DeleteRowDetail(po_Connection, po_Transaction, po_KeyCode);
        //    }
        //}

        public DataSet GetDataSet()
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDataSet();
            }
            else
            {
                return oDataAcess.GetDataSet();
            }
        }

        public DataSet GetDataSet(string ps_Code)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDataSet(ps_Code);
            }
            else
            {
                return oDataAcess.GetDataSet(ps_Code);
            }
        }

        public DataTable GetDetailTable(string ps_Stt)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetDetailTable(ps_Stt);
            }
            else
            {
                table= oDataAcess.GetDetailTable(ps_Stt);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public bool SaveDetailTable(object ps_KeyCode, DataTable po_DetailDataTable)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveDetailTable(ps_KeyCode, po_DetailDataTable);
            }
            else
            {
                return oDataAcess.SaveDetailTable(ps_KeyCode, po_DetailDataTable);
            }
        }

        public int SaveRow(bool pb_NewChecked, DataRow row)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveRow(pb_NewChecked, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
            }
            else
            {
                return oDataAcess.SaveRow(pb_NewChecked, row);
            }
        }

        //public int SaveRowDetail(SqlConnection po_Connection, SqlTransaction po_Transaction, object po_MasterKey, DataRow row)
        //{
        //    if (AdapterInstance.IsRemoteConnected)
        //    {
        //        return wDataAcess.SaveRowDetail(po_Connection, po_Transaction, po_MasterKey, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
        //    }
        //    else
        //    {
        //        return oDataAcess.SaveRowDetail(po_Connection, po_Transaction, po_MasterKey, row);
        //    }
        //}
    }
}

